var utils = require('../../../../utils/util.js')
Page({
  data: {
    userinfo: wx.getStorageSync("userinfo"),
    money:'',
    fee:'0.00',
    real_money:'0.00'
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      utils.updateUserinfo();
        utils.checkLogin();
        this.setData({
            userinfo:wx.getStorageSync("userinfo")
        })
  },
  setMoney:function(e){
      var that = this;
      var money = e.detail.value;
      if (money=='') {
        that.setData({
          fee:'0.00',
          real_money:'0.00'
        })
        return false;
      }
      var data = {
          url:"/zfcom/com/deploy",
          uuid:'sytoye_fee',
      };
      utils.request(data).then(function(res){
          if (res.code == 0) {
            var fee = parseFloat(money) * res.data.sytoye_fee;
              var real_money = parseFloat(money)-parseFloat(fee);
              that.setData({
                  fee: fee,
                  real_money:real_money,
                  money:money
              })
          }
      });
  },
  symtomye:function(){
      var that = this;
      var token = wx.getStorageSync("userinfo").wap_token;
      var data = {
          url:"/yluser/ordermtom/sytoye",
          token:token,
          money:this.data.money,
      };
      utils.request(data).then(function(res){
          if (res.code == 0) {
            utils.updateUserinfo();
            wx.showToast({
                title: '转出成功',
                icon: 'none',
                duration: 1500
            });
            setTimeout(function(){
              wx.switchTab({
                  url: "/pages/my/usercenter/index",
              })
            },1000);
            
          }else{
              wx.showToast({
                  title: res.msg,
                  icon: 'none',
                  duration: 1500
              }) 
          }
      });
  }

})